import 'package:mi_mang_flutter/network/client.dart';
import 'package:mi_mang_flutter/network/response_data.dart';

/// 邮箱管理接口
class EmailApi {
  /// 发送绑定邮箱验证码
  static const String API_EMAIL_SEND_BIND_CODE = "/api/email/send_bind_code";

  /// 账号绑定邮箱
  static const String API_EMAIL_BIND_EMAIL = "/api/email/bind_email";

  /// 发送绑定邮箱验证码
  /// [email] 待绑定的邮箱号
  /// [emailType] 验证码类型(1. 绑定邮箱验证码; 2. 修改密码验证码)
  static Future<ResponseData> sendEmailCode(
    String? email, {
    String? emailType,
  }) {
    return client.post(
      API_EMAIL_SEND_BIND_CODE,
      queryParameters: {
        "email": email,
        "emailType": emailType,
      },
    );
  }

  /// 账号绑定邮箱
  ///
  /// [code] 发送到邮箱的验证码
  ///
  /// [email] 邮箱号
  static Future<ResponseData> bindEmail(String code, String? email) {
    return client.post(
      API_EMAIL_BIND_EMAIL,
      data: {
        "code": code,
        "email": email,
      },
    );
  }
}
